#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
@File    :   try_except.py
@Time    :   2025/01/17 20:33:33
@Author  :   xiangyu Chen
@Version :   1.0
@Contact :   yu112yu@sina.com
@License :   (C)Copyright 2017-2018, Liugroup-NLPR-CASIA
@python_requires    :   None
@Desc    :   None
'''

import os
import pprint
import sys


class NoCall(object):
    def __init__(self, name):
        self.name = name


noCall = NoCall('HAHA')
try:
    noCall()
except AttributeError as e:  # 依次序直到捕获对应类型的异常即停止。
    print('AttributeError:', e)

except Exception as e:
    except_type, except_value, except_traceback = sys.exc_info()
    except_file = os.path.split(
        except_traceback.tb_frame.f_code.co_filename)
    exc_dict = {
        "报错类型": except_type,
        "报错信息": except_value,
        "报错文件": except_file,
        "报错行数": except_traceback.tb_lineno,
    }
    pprint.pprint(exc_dict)
except TypeError as e:
    print('TypeError:', e)
